﻿using System;
using UnityEngine;

public static class ResLoader {
	#region 同步加载
	public static T LoadRes<T>(string path) where T : UnityEngine.Object {
		T res = Resources.Load<T>(path);
		if (res == null) {
			Debug.LogError($"加载资源失败:失败路径为:{path}");
			return null;
		}
		return res;
	}
	public static T[] LoadAllRes<T>(string path) where T : UnityEngine.Object {
		T[] res = Resources.LoadAll<T>(path);
		if (res == null || res.Length == 0) {
			Debug.LogError($"加载资源失败:失败路径为:{path}");
			return null;
		}
		return res;
	}

	public static GameObject LoadPrefab(string path)
		=> LoadRes<GameObject>(path);

	public static GameObject[] LoadAllPrefab(string path)
	=> LoadAllRes<GameObject>(path);
	public static GameObject LoadPrefabAndInstantiate(string path, Transform parent = null)
		=> UnityEngine.Object.Instantiate(LoadRes<GameObject>(path), parent);
	#endregion
}